﻿using UnityEngine;
using System.Collections;

public class UIManager : MonoBehaviour {

    GUIStyle myStyle = new GUIStyle();
    Font myFont;

	void OnGUI() {
		
		// Main menu scene
		if(Application.loadedLevel == 0) {
            int yOffset = 100;
			// You can use the Screen.width and Screen.height properties to get the total dimensions of the screen space available in the player. 
			//GUI.Box(new Rect(Screen.width/2 - 50, Screen.height/2 + yOffset - 45, 100, 90), "");
			
			//if(GUI.Button(new Rect(Screen.width/2 - 40 - xOffset, Screen.height/2 + yOffset /*- 20*/, 80, 20), "PLAY")) {
			if(GUI.Button(new Rect(Screen.width/2 - 40, Screen.height/2 + yOffset, 80, 20), "PLAY")){
                print("Let's Play!");
				Application.LoadLevel(2);
			}
			
			//if(GUI.Button(new Rect(Screen.width/2 - 40 + xOffset, Screen.height/2 + yOffset /*+ 10*/, 80, 20), "How to Play")){
			//	Application.LoadLevel(2);				
			//	print("How do I play?");
			//}
		}
		// In play
		else if(Application.loadedLevel == 1) {
            myFont = (Font)Resources.Load("Fonts/DecoCaps", typeof(Font));
            myStyle.font = myFont;

			string numDead = string.Format("Dead\n{0}", GameManager.sheepDead.ToString());
            string numCollected = string.Format("Collected\n{0}", GameManager.sheepCollected.ToString());

            GUI.Label(new Rect(Screen.width - (Screen.width - 100), Screen.height - 50, 100, 40), numDead, myStyle);
            GUI.Label(new Rect(Screen.width - 200, Screen.height - 50, 100, 40), numCollected, myStyle);
		}
		// Help menu
		else if(Application.loadedLevel == 2){
			//GUI.Box(new Rect(Screen.width/2 - 150, Screen.height/2 - 200, 300, 400), "");
			// Add GUI Text
			if(GUI.Button(new Rect(Screen.width/2 - 75, Screen.height/2 +225, 150, 20), "PLAY")){
				Application.LoadLevel(1);
				print("PLAY");
			}
		}
        // Lose Screen
        else if (Application.loadedLevel == 3)
        {
            if (GUI.Button(new Rect(Screen.width / 2 - 75, Screen.height / 2 + 200, 150, 20), "Back to Main Menu"))
            {
                Application.LoadLevel(0);
                print("Back to Main.");
            }
            showStats();
            // Add GUI Text

        }

        // Win Screen
        else if (Application.loadedLevel == 4)
        {
            if (GUI.Button(new Rect(Screen.width / 2 - 75, Screen.height / 2 + 200, 150, 20), "Back to Main Menu"))
            {
                Application.LoadLevel(0);
                print("Back to Main.");
            }
            showStats();
        }
	}

    void showStats()
    {
        GUI.Label(new Rect(Screen.width / 2 - 30, Screen.height / 2 + 60, 150, 30), "Score");

        GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height / 2 + 80, 170, 60), string.Format("Sheep Collected:\t{0}\nTotal Sheep:\t\t\t{1}\nPercent Saved:\t\t{2}%", GameManager.sheepCollected, GameManager.count, Mathf.Round(((float)(GameManager.sheepCollected) / (float)(GameManager.count)) * 100)));
    }
}
